import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kw):
        super(MyFrame, self).__init__(*args, **kw)

        # 创建一个面板
        panel = wx.Panel(self)

        # 创建一个垂直布局的 sizer
        vbox = wx.BoxSizer(wx.VERTICAL)

        # 创建一个 Slider
        self.slider = wx.Slider(panel, value=0, minValue=0, maxValue=1, style=wx.SL_HORIZONTAL | wx.SL_LABELS)
        vbox.Add(self.slider, 0, wx.ALL, 10)

        # 绑定 Slider 的事件
        self.Bind(wx.EVT_SLIDER, self.OnSlider, self.slider)

        # 设置面板的布局
        panel.SetSizer(vbox)

        # 设置窗口大小
        self.SetSize((300, 200))
        self.SetTitle("滑块式开关示例")
        self.Centre()

    def OnSlider(self, event):
        # 获取滑块的值
        value = self.slider.GetValue()
        if value == 1:
            print("开关已开启")
        else:
            print("开关已关闭")

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()
